package edu.bw.service.impl;

import cn.hutool.core.bean.BeanUtil;
import edu.bw.dao.UserDao;
import edu.bw.dao.impl.UserDaoImpl;
import edu.bw.dto.InsertUserForm;
import edu.bw.dto.UpdateUserForm;
import edu.bw.dto.selectUserByConditionForm;
import edu.bw.pojo.User;
import edu.bw.service.UserService;
import edu.bw.utils.PageUtils;

import java.util.List;
import java.util.Map;

public class UserServiceImpl implements UserService {
    UserDao userDao=new UserDaoImpl();
    @Override
    public Integer userLogin(User user) {
        return userDao.userLogin(user);
    }

    @Override
    public PageUtils selectUserByCondition(selectUserByConditionForm params) {
        List<Map<String,Object>> list=userDao.selectUserByCondition(params);
        int start=(params.getPage()-1)*params.getLength();
        Long count=userDao.selectByConditionCount(params);
        return new PageUtils(list,count,start,params.getLength());
    }

    @Override
    public Integer insertUser(InsertUserForm insertUserForm) {
        User user = new User();
        BeanUtil.copyProperties(insertUserForm,user);
        return  userDao.insertUser(user);
    }

    @Override
    public List<Map<String, Object>> selectById(Integer userId) {
        return userDao.selectById(userId);
    }

    @Override
    public Integer updateUser(UpdateUserForm updateUserForm) {
        User user = new User();
        BeanUtil.copyProperties(updateUserForm,user);
        user.setId(updateUserForm.getUserId());
        return userDao.updateUser(user);
    }

    @Override
    public Integer deleteByIds(List<Integer> ids) {
        return  userDao.deleteByIds(ids);
    }
}
